package com.gewu.bookeeping.View.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TableLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.gewu.bookeeping.R;
import com.gewu.bookeeping.View.ItemFragment.twoItem1Fragment;
import com.gewu.bookeeping.View.ItemFragment.twoItem2Fragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class twoFragment extends Fragment {

    private Toolbar toolbar;
    private TextView title;
    private ViewPager viewById;
    private TabLayout oneGroup;
    private String [] item = {"月账单","年账单"};
    private List<Fragment> fragments = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = LayoutInflater.from(container.getContext()).inflate(R.layout.activity_two_fragment, container, false);
        initView(inflate);
        return inflate;
    }

    private void initView(View inflater) {
        toolbar = (Toolbar) inflater.findViewById(R.id.toolbar);
        title = (TextView) inflater.findViewById(R.id.title);
        viewById = inflater.findViewById(R.id.viewpager);
        oneGroup = inflater.findViewById(R.id.one_tab);
        toolbar.setTitle("账单明细");
        toolbar.setLogo(R.mipmap.two_ic);

        fragments.add(new twoItem1Fragment());
        fragments.add(new twoItem2Fragment());

        oneGroup.setupWithViewPager(viewById);

        this.viewById.setAdapter(new FragmentStatePagerAdapter(getChildFragmentManager()) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return item.length;
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return item[position];
            }
        });
    }
}